﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using WcfBackend;

public partial class ResultPage : System.Web.UI.Page
{
    private static WcfFoodAndAllergiesClient wcf;
    private static Recipe recipe;
    private List<Product> ingredients;
    private List<Recipe> recipeResults;

    protected void Page_Load(object sender, EventArgs e)
    {
        wcf = new WcfFoodAndAllergiesClient();

        if (string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            Response.Redirect("RecipeSearch.aspx");
        }
        else
        {
            int id = int.Parse(Request.QueryString["id"]);
            recipe = wcf.GetRecipeById(id);
            recipeName.Text = recipe.Name;
            typeOfRecipe.InnerText = recipe.TypeOf;
            recipeSummary.InnerText = recipe.Summary;
            serverings.InnerText = recipe.Servings + " person(er)";

            ingredients = wcf.GetProductByRecipe(recipe).ToList();


            foreach (Product p in ingredients)
            {
                HtmlGenericControl li = new HtmlGenericControl("li");
                li.Controls.Add(new Label() { Text = p.Name + " " + p.amount + " " +p.unit + "\r\n" });

                repIngredients.Controls.Add(li);
            }

            recipeImg.Src = "images/intet_billede.jpg";


        }

    }
    protected void btnIngredient_Click(object sender, EventArgs e)
    {
        Session["Products"] = ingredients; 
        Response.Redirect("ShoppingList.aspx");
    }
}